/*
 * Toolbar.java
 *
 * Created on 2007. mC!rcius 12., 16:50
 *
 */

package laborhazi;
import java.util.ArrayList;

/**
 * Contains the tools, and manages them
 * @author nyuszik
 */
public class Toolbar {
    private Tool actual;
    private int barricadeNum = 0, parachuteNum = 0, 
    			erectorNum = 0, drillNum = 0, explosiveNum = 0 ;
    private int actNum = 0;
    public Tool[] tools;
    public ArrayList list;
    public Field field; //PRIVATE
    
    /** Creates a new instance of Toolbar */
    public Toolbar(Field f) {
        /** Just for skeleton testing */
        field = f;
        list = new ArrayList();
    }
    /** 
     * Highlights a tool for future usage
     * @param tool the highlighted tool
     */
    public void highlight(Tool tool) {
    	int i;
    	
    	for (i = 0; i < list.size(); ++i) {
    		if ( tool.equals((Tool) list.get(i)) ) {
    			actual = (Tool)list.get(i);	
    			actNum = i;
    			return ;
    		} else {
    			actual = null;
    		}
    	}
    }
    /** 
     * Adds a new tool
     * @param newtool the tool to be added
     */
    public void add(Tool tool) {
    	if (tool.equals(new Barricade())) 
			++barricadeNum;
		if(tool.equals(new Erector()))
			++erectorNum;
		if(tool.equals(new Drill()))
			++drillNum;
		if(tool.equals(new Explosive()))
			++explosiveNum;
		if(tool.equals(new Parachute()))
			++parachuteNum;
    	System.out.println(tool.toString() + " added");
    	list.add(tool);
    }
    /** 
     * Gives the highlighted tool to a lemming
     * @param lemming the lemming who recieves the tool
     */
    public void give(Lemming lemming) {
        if (actual != null && lemming.recieveTool(actual) == true) {
            remove(actual);
            actual = null;
        }
    }
    /** 
     * Gives the highlighted tool to a setlemming
     * @param setLemming the setLemming who recieves the tool
     */
    public void give(SetLemming setLemming) {
        if (actual != null && setLemming.recieveTool(actual) == true) {
            remove(actual);
            actual = null;
        }
    }
    /** 
     * Removes a tool from the Toolbar
     * @param tool the tool to be removed
     */
    public void remove(Tool tool) {
    	//int i;
    	
    	if ( actual.equals(new Barricade()) ) {
    		--barricadeNum;
    	}
    	if ( actual.equals(new Parachute()) ) {
    		--parachuteNum;
    	}
    	if ( actual.equals(new Explosive()) ) {
    		--explosiveNum;
    	}
    	if ( actual.equals(new Drill()) ) {
    		--drillNum;
    	}
    	if ( actual.equals(new Erector()) ) {
    		--erectorNum;
    	}
    	list.remove(actNum);
    }
    
    public int getBarricade() {
    	
    	return barricadeNum;
    }
    public int getParachute() {
    	
    	return parachuteNum;
    }
    public int getExplosive() {
    	
    	return explosiveNum;
    }
    public int getDrill() {
    	
    	return drillNum;
    }
    public int getErector() {
    	
    	return erectorNum;
    }
}
